<?php
declare (strict_types = 1);

namespace app\home\controller;

use app\home\model\WebCate;
use app\home\model\WebConfig;
use app\home\model\WebSwiper;
use think\facade\Lang;
use think\facade\View;

class Base{

    protected $config;
    protected $webcate;
    protected $swiper;


    protected $site=[];
    protected $nav;

    public function __construct(){

        $this->config = new WebConfig();
        $this->webcate = new WebCate();
        $this->swiper = new WebSwiper();

        $this->init();
        $this->navigator();

    }

    //初始网站基本信息
    protected function init(){

        $data = $this->config->select()->toArray();
        if(!empty($data)){
            for($i=1;$i<count($data);$i++){
                $this->site[$data[$i]["config_name"]]=$data[$i]["config_value"];
            }
        }
        View::assign(["site"=>$this->site]);
        
    }

    //获取栏目列表
    protected function navigator(){

        $this->nav = $this->webcate->where(["isshow"=>1,"parent"=>0])->order("sort desc,id desc")->select()->toArray();
        View::assign(["nav"=>$this->nav]);

    }

    //获取轮播图
    protected function getSwiper($alias,$num=1,$lang='zh-cn'){
        return  $this->swiper->where(["alias"=>$alias,"isshow"=>1,"lang"=>$lang])->order("sort desc,id desc")->limit($num)->select()->toArray();
    }

    //设置网站语言类型
    protected function setLang($lang){

        $lang = !empty($lang) ? $lang : "zh-cn";

        Lang::setLangSet($lang);

        cookie("xmcms_lang",$lang);

    }






}
